<template>
  <div class="app-container">
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :inline="true"
      :model="queryParams"
      size="small"
    >
      <el-form-item label="应用编码" prop="appCode">
        <el-input
          v-model="queryParams.appCode"
          clearable
          placeholder="请输入应用编码"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="资源模块名称" prop="modularName">
        <el-input
          v-model="queryParams.modularName"
          clearable
          placeholder="请输入资源模块名称"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="请求方式" prop="httpMethod">
        <el-select
          v-model="queryParams.httpMethod"
          clearable
          placeholder="请输入请求方式"
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.sys_http_method"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="dateRange"
          end-placeholder="结束日期"
          range-separator="-"
          start-placeholder="开始日期"
          style="width: 240px"
          type="daterange"
          value-format="yyyy-MM-dd"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          icon="el-icon-search"
          size="mini"
          type="primary"
          @click="handleQuery"
        >搜索
        </el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置
        </el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="resourceList"
    >
      <el-table-column label="应用编码" prop="appCode" width="150"/>
      <el-table-column
        :show-overflow-tooltip="true"
        label="资源名称"
        prop="resourceName"
        width="300"
      />
      <el-table-column
        :show-overflow-tooltip="true"
        label="资源模块名称"
        prop="modularName"
        width="150"
      />
      <el-table-column label="接口地址" prop="url" width="300"/>
      <el-table-column label="请求方式" prop="httpMethod" width="100"/>
      <el-table-column
        align="center"
        class-name="small-padding fixed-width"
        label="创建时间"
        prop="createTime"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :limit.sync="queryParams.pageSize"
      :page.sync="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listResource,} from "@/api/system/resource";

export default {
  name: "Resource",
  dicts: ["sys_http_method"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 接口资源表格数据
      resourceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //是否显示弹出层(分配接口)
      openAuthApi: false,
      menuExpand: false,
      menuNodeAll: false,
      resourceExpand: true,
      resourceNodeAll: false,
      // 日期范围
      dateRange: [],
      // 菜单列表
      menuOptions: [],
      // 资源列表
      resourceOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        appCode: undefined,
        modularName: undefined,
        httpMethod: undefined,
      },
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label",
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listResource(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.resourceList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    // 表单重置
    reset() {
      if (this.$refs.menu != undefined) {
        this.$refs.menu.setCheckedKeys([]);
      }
      (this.menuExpand = false),
        (this.menuNodeAll = false),
        (this.resourceExpand = true),
        (this.resourceNodeAll = false),
        (this.form = {
          roleId: undefined,
          appCode: undefined,
          modularName: undefined,
          roleSort: 0,
          httpMethod: undefined,
          menuIds: [],
          resourceIds: [],
          menuCheckStrictly: true,
          resourceCheckStrictly: true,
          remark: undefined,
        });
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
